/*
 * Copyright (c) 2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr.h>
#include <device.h>
#include <gpio.h>

// #define LED_PORT  DT_GPIO_LEDS_LED_1_GPIO_CONTROLLER
// #define LED_PIN   DT_GPIO_LEDS_LED_1_GPIO_PIN

// #define LED_PORT  DT_GPIO_LEDS_LED_2_GPIO_CONTROLLER
// #define LED_PIN   DT_GPIO_LEDS_LED_2_GPIO_PIN

#define LED_PORT DT_GPIO_LEDS_LED_3_GPIO_CONTROLLER
#define LED_PIN DT_GPIO_LEDS_LED_3_GPIO_PIN

// #define LED_PORT  DT_GPIO_LEDS_LED_4_GPIO_CONTROLLER
// #define LED_PIN   DT_GPIO_LEDS_LED_4_GPIO_PIN

/* 1000 msec = 1 sec */
#define SLEEP_TIME 200

void main(void)
{
	int cnt = 0;
	struct device *dev;

	printk("Blink start! %s\n", CONFIG_BOARD);

	dev = device_get_binding(LED_PORT);
	if (dev != NULL)
	{
		/* Set LED pin as output */
		gpio_pin_configure(dev, LED_PIN, GPIO_DIR_OUT);
	}
	else
	{
		printk("dev is null\r\n");
	}

	while (1)
	{
		/* Set pin to HIGH/LOW every 1 second */
		if (dev)
			gpio_pin_write(dev, LED_PIN, cnt % 2);
		//printk("Blink %d\n", cnt);
		k_sleep(SLEEP_TIME);
		cnt++;
	}
}
